﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace _通用测试
{
    class Program
    {
        static void Main(string[] args)
        {
            B();

            #region 实体数据构建
            //List<Student> students = new List<Student>()
            //{
            //    new Student(){ Id=1, Name="李明", Birthday=DateTime.Now.AddYears(-25), Sex="男" },
            //    new Student(){ Id=2, Name="李红", Birthday=DateTime.Now.AddYears(-22), Sex="女" },
            //    new Student(){ Id=3, Name="王磊", Birthday=DateTime.Now.AddYears(-26), Sex="男" },
            //};

            //List<Course> courses = new List<Course>()
            //{
            //    new Course(){ Id=1, CourseName="语文", TearchId=3 },
            //    new Course(){ Id=2, CourseName="数学", TearchId=1 }
            //};


            //List<Sc> scs = new List<Sc>()
            //{
            //    new Sc(){ CourseId=1, StuId=1, Score=85 },
            //    new Sc(){ CourseId=1, StuId=2, Score=76 },
            //    new Sc(){ CourseId=2, StuId=1, Score=89 },
            //    new Sc(){ CourseId=2, StuId=2, Score=66 },
            //    new Sc(){ CourseId=3, StuId=1, Score=98 },
            //    new Sc(){ CourseId=3, StuId=2, Score=62 }
            //}; 
            #endregion


            #region 两列List 查询
            //List<Seacher> seachers = new List<Seacher>()
            //{
            //    new Seacher(){ NameFirst="渣钡抄", NameSecond="时贮装" },
            //     new Seacher(){ NameFirst="盈探等", NameSecond="棵倦苹" }
            //};


            //List<string> ACode = seachers.Select(x => x.NameFirst).ToList();
            //List<string> BCode = seachers.Select(x => x.NameSecond).ToList();



            //using (var db = new BaseContext())
            //{

            //    //var list1 = db.Student.ToList();
            //    //var list = (from a in db.Student
            //    //            where ACode.Contains(a.StuNum)
            //    //            || BCode.Contains(a.Name)
            //    //            orderby a.Class ascending,a.ClassNum descending
            //    //            select a).ToList();
            //    //var list = db.Student.OrderBy(x => x.Class).ThenByDescending(x => x.Sex).ToList();

            //}

            #endregion

            //ReflectTest();

            #region 自定义排序
            //List<int> list = new List<int> { 0, 1, 3, 1, 5, 0, 0, 6, 7, 8, 9 };
            //list.Sort((x, y) =>
            //{
            //    if (x != 1)
            //    {
            //        if (y != 1)
            //        {
            //            if (x > y)
            //            {
            //                return 1;
            //            }
            //            else
            //            {
            //                return -1;
            //            }
            //        }
            //        return 1;
            //    }
            //    return -1;
            //});
            //var list2 = list;
            #endregion

            #region 扩展方法
            //object o = null;
            //int res = Convert.ToInt32(o);

            //string s = "123";
            //if (s.Contains(""))
            //{
            //    Console.WriteLine("true");
            //}
            //else
            //{
            //    Console.WriteLine("false");
            //} 
            #endregion

            ////B b = new B();
            ////b.Prints();

            //int[] nums = { 5,7,9,0,2,3 };
            //var query = from a in nums
            //            where a > 1
            //            orderby a descending
            //            select a;

            //nums = nums.Add(6);

            //for (int i = 0; i < nums.Length; i++)
            //{
            //    Console.Write(nums[i]+" ");
            //}

            //Console.WriteLine("\r\n移除之后");

            //nums = nums.Remove(2);

            //for (int i = 0; i < nums.Length; i++)
            //{
            //    Console.Write(nums[i]+" ");
            //}

        }

        static void SqlConn()
        {
            string username = "";
            string password = "";
            string ConnStr = "";
            string sql = "select count(1) from users where Username='" + username + "' and Password = '" + password + "'";
            SqlConnection conn = new SqlConnection(ConnStr);
            conn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandText = sql;
            cmd.CommandType = System.Data.CommandType.Text;
            int count = Convert.ToInt32(cmd.ExecuteScalar());
            conn.Dispose();
            conn.Close();
            cmd.Dispose();

            if (count > 0)
            {
                Console.WriteLine("登录成功");
            }
            else
            {
                Console.WriteLine("登陆失败");
            }
        }

        public static void ReflectTest()
        {

            PersonInfo person = new PersonInfo();
            person.Id = 1;
            person.Name = "张三";
            person.Interest = "足球";
            person.Birthday = DateTime.Now.AddYears(-28);
            person.Comm = new Comm();
            person.Comm.Property1 = "123";
            person.Comm.Property2 = "456";

            System.Reflection.PropertyInfo[] propertys = person.GetType().GetProperties();
            PropertyInfo info = propertys.Where(x => x.Name == "Comm").FirstOrDefault();
            Comm c = info.GetValue(person, null) as Comm;
            if (info != null)
            {
                PropertyInfo[] CommInfo = c.GetType().GetProperties();
                CommInfo[1].SetValue(c, "789");
            }

            PersonInfo RelPerson = person;
        }


        public static void A()
        {
            try
            {
                string a = "hh";
                int b = Convert.ToInt32(a);
            }
            catch (Exception ex)
            {
                string msg = ex.Message.ToString();
                //throw ex;
            }
        }

        public static void B()
        {
            try
            {
                A();
            }
            catch (Exception ex)
            {
                string msg = ex.Message.ToString();
                throw;
            }
        }
    }

    public class A
    {
        public A()
        {
            Prints();
        }
        public virtual void Prints() { }
    }

    public class B : A
    {
        int x = 1;
        int y;
        public B()
        {
            y = -1;
        }
        public override void Prints()
        {
            Console.WriteLine(x + "," + y);
        }
    }

    public class Seacher
    {
        public string NameFirst { get; set; }

        public string NameSecond { get; set; }
    }

}
